home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / EnterAct Stuff / Read Res project / Read_Res Source / Code_Main.c next >
Encoding:
C/C++ Source or Header  |  1997-02-07  |  9.3 KB  |  384 lines  |  [TEXT/KEEN]

  1. /***********main file for code resource**************/
  2. /* Copyright © 1991, 1992 the Free Software Foundation, Inc.
  3.  *         This file is free software; you can redistribute or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 1, or any later version.
  6.  *         This file is distributed in the hope that it will be useful,
  7.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9.  * GNU General Public License for more details.
  10.  *         You should have received a copy of the GNU General Public License
  11.  * along with GAWK; see the file "COPYING hAWK". If not, write to
  12.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  13.  * Written for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
  14.    Revised May 1992: new setup/restore a4 strategy.
  15.    Revised Feb 97: converted to CodeWarrior.
  16.  */
  17.  
  18. #ifdef powerc
  19. #include <CodeFragments.h>
  20. #else
  21. #include <A4Stuff.h>
  22. #endif
  23.  
  24. #include <string.h>
  25. #include "AppCodeComm.h"
  26.  
  27. #ifndef NULL
  28. #define NULL        ((void *) 0)
  29. #endif
  30.  
  31. /* Global copy of the AppCodeComm struct passed from the application
  32. to the code resource - gacc stands for Global Application-Code resource
  33. Communication. Gacc.*/
  34. AppCodeComm    gacc;
  35.  
  36. /* Global to indicate if calling app's event loop has been made
  37. available and should call it */
  38. Boolean gConcurrent;
  39.  
  40. #ifndef powerc
  41. long _app_a4;
  42. #endif
  43.  
  44. /* "main" call for the specific code resource */
  45. extern short DoReadRes(void); /* see Read_Res.c */
  46.  
  47. /* Protos for functions in this file */
  48. void main(ACCPtr ac);
  49. /* Callbacks, to be made available to other files */
  50. short InDictionary(char *tokenName);
  51. Boolean HasInDictionary(void);
  52. Handle GetFrontText(Boolean getItAll);
  53. Boolean HasGetFrontText(void);
  54. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  55.         short *vRefNumPtr, char *fileName, Boolean clearFlag);
  56. Boolean HasGetNextMultiFile(void);
  57. short OKStopAlert(Ptr cstringPtr);
  58. Boolean HasOKStopAlert(void);
  59. void MemoryAlert(void);
  60. Boolean HasMemoryAlert(void);
  61. short GetScreenHeight(void);
  62. Boolean HasGetScreenHeight(void);
  63. short GetScreenWidth(void);
  64. Boolean HasGetScreenWidth(void);
  65. void SetWatchCursor(void);
  66. Boolean HasSetWatchCursor(void);
  67. void DoEventLoopOnce(void);
  68. Boolean HasDoEventLoopOnce(void);
  69. Handle GetTheClip(void);
  70. Boolean HasGetTheClip(void);
  71. short PutTheClip(char *newClipStr);
  72. Boolean HasPutTheClip(void);
  73.  
  74. // Kludge required by CodeWarrior 6
  75.  void (*__exit_proc__)(void);
  76.  
  77. /* The "main" that is called from the running application. This file is
  78. kept small and best in its own segment because lots of other things get piled
  79. into here as well - the jump table for the code resource, for example.
  80. So do the bare minimum - set up the global register reference, call the
  81. code resource main function, pass back a result code, and restore the
  82. a4 register. Functions below main() are the extension interface
  83. functions, which must be in this file to make use of the little functions
  84. above that save and restore a4. They all check to see that the extension
  85. in question has been passed from the application, and if not either return
  86. a zero or NULL or return a safe general value. No extension should be
  87. essential to the operation of the code resource.
  88. */
  89. /* results:
  90. <= -3 : counts as -1 at present
  91. -2 : show stderr
  92. -1 : user cancelled or error during dialog - no run
  93. 0  : run OK, do nothing special after
  94. 1  : show stdout
  95. 2  : show and select stdout
  96. > 2 : no action at present (counts as equivalent to 0)
  97. */
  98. void main(ACCPtr ac)
  99.     {
  100.     short    result;
  101. #ifndef powerc
  102.     long     _app_a4 = SetCurrentA4();    //sets A4 to point to your code resources globals
  103.                                     //it returns what's currently in A4 so you can restore it later
  104.                                     //SetCurrentA4 and SetA4 are analogous to SetCurrentA5 and SetA5
  105. #endif
  106.     
  107.     /* Uncomment this for a version "sanity check": **************
  108.     if (ac->version < 0 || ac->version > 100)
  109.         {
  110.         OKStopAlert("Version number passed by calling application \
  111. is impossible. Please fix the application before trying again.");
  112.         ac->result = -1;
  113.         asm
  114.             {
  115.             move.l _app_a4, a4
  116.             }
  117.         return;
  118.         }
  119.     ********** end version check */
  120.     
  121.     gacc = *ac; /* make a global copy */
  122.     if (gacc.version <= 1)
  123.         {
  124.         gacc.DoEventLoopOnce_Ext = NULL;
  125.         gacc.GetAppClip_Ext = NULL;
  126.         }
  127.     if (HasDoEventLoopOnce())
  128.         gConcurrent = TRUE;
  129.     else
  130.         gConcurrent = FALSE;
  131.  
  132.     /* call 'true' main of code resource */
  133.     result = DoReadRes();
  134.     ac->result = result;
  135. #ifndef powerc
  136.     //Reset A4 to what it was when we entered.  The return value (which we ignore) is our
  137.     //global pointing A4.
  138.     (void)SetA4(_app_a4);
  139.     /* return nothing - communication via (ga)ac->result */
  140. #endif
  141.     }
  142.  
  143. /* Extension functions. See Call_Resource.c for details
  144. on what these do. EnterAct supplies them all, but your application
  145. doesn't have to supply any of them, and your code resource should
  146. not rely on any of them being available.
  147.  
  148. A Boolean companion function for each extension reports whether
  149. the extension is available for use. 
  150. */
  151.  
  152. short InDictionary(char *tokenName)
  153.     {
  154.     ACCPtr    laccp = &gacc; /* must use a local pointer if 68K */
  155.     short    ret;
  156. #ifndef powerc
  157.     long cura4 = SetA4(_app_a4);
  158. #endif
  159.     if (laccp->InDictionary_Ext != NULL)
  160.         ret = (*(laccp->InDictionary_Ext))(tokenName);
  161.     else
  162.         ret = 0;
  163. #ifndef powerc
  164.     (void)SetA4(cura4);
  165. #endif
  166.     return(ret);
  167.     }
  168.  
  169. Boolean HasInDictionary()
  170.     {
  171.     return(gacc.InDictionary_Ext != NULL);
  172.     }
  173.  
  174. Handle GetFrontText(Boolean getItAll)
  175.     {
  176.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  177.     Handle    ret;
  178. #ifndef powerc
  179.     long cura4 = SetA4(_app_a4);
  180. #endif
  181.     if (laccp->GetFrontText_Ext != NULL)
  182.         ret = (*(laccp->GetFrontText_Ext))(getItAll);
  183.     else
  184.         ret = NULL;
  185. #ifndef powerc
  186.     (void)SetA4(cura4);
  187. #endif
  188.     return(ret);
  189.     }
  190.  
  191. Boolean HasGetFrontText()
  192.     {
  193.     return(gacc.GetFrontText_Ext != NULL);
  194.     }
  195.  
  196. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  197.         short *vRefNumPtr, char *fileName, Boolean clearFlag)
  198.     {
  199.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  200. #ifndef powerc
  201.     long cura4 = SetA4(_app_a4);
  202. #endif
  203.     if (laccp->GetNextMultiFile_Ext != NULL)
  204.         (*(laccp->GetNextMultiFile_Ext))(panePtr, indexPtr,
  205.             vRefNumPtr, fileName, clearFlag);
  206.     else
  207.         *indexPtr = -1;
  208. #ifndef powerc
  209.     (void)SetA4(cura4);
  210. #endif
  211.     }
  212.  
  213. Boolean HasGetNextMultiFile()
  214.     {
  215.     return(gacc.GetNextMultiFile_Ext != NULL);
  216.     }
  217.  
  218. short OKStopAlert(Ptr cstringPtr)
  219.     {
  220.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  221.     short    ret;
  222. #ifndef powerc
  223.     long cura4 = SetA4(_app_a4);
  224. #endif
  225.     if (laccp->OKStopAlert_Ext != NULL)
  226.         ret = (*(laccp->OKStopAlert_Ext))(cstringPtr);
  227.     else
  228.         ret = 0;
  229. #ifndef powerc
  230.     (void)SetA4(cura4);
  231. #endif
  232.     return(ret);
  233.     }
  234.  
  235. Boolean HasOKStopAlert()
  236.     {
  237.     return(gacc.OKStopAlert_Ext != NULL);
  238.     }
  239.  
  240. void MemoryAlert()
  241.     {
  242.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  243. #ifndef powerc
  244.     long cura4 = SetA4(_app_a4);
  245. #endif
  246.     if (laccp->MemoryAlert_Ext != NULL)
  247.         (*(laccp->MemoryAlert_Ext))();
  248. #ifndef powerc
  249.     (void)SetA4(cura4);
  250. #endif
  251.     }
  252.  
  253. Boolean HasMemoryAlert()
  254.     {
  255.     return(gacc.MemoryAlert_Ext != NULL);
  256.     }
  257.  
  258. short GetScreenHeight()
  259.     {
  260.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  261.     short        ret;
  262. #ifndef powerc
  263.     long cura4 = SetA4(_app_a4);
  264. #endif
  265.     if (laccp->GetScreenHeight_Ext != NULL)
  266.         ret = (*(laccp->GetScreenHeight_Ext))();
  267.     else
  268.         ret = 342; /* minimum possible */
  269. #ifndef powerc
  270.     (void)SetA4(cura4);
  271. #endif
  272.     return(ret);
  273.     }
  274.  
  275. Boolean HasGetScreenHeight()
  276.     {
  277.     return(gacc.GetScreenHeight_Ext != NULL);
  278.     }
  279.  
  280. short GetScreenWidth()
  281.     {
  282.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  283.     short        ret;
  284. #ifndef powerc
  285.     long cura4 = SetA4(_app_a4);
  286. #endif
  287.     if (laccp->GetScreenWidth_Ext != NULL)
  288.         ret = (*(laccp->GetScreenWidth_Ext))();
  289.     else
  290.         ret = 512; /* minimum possible */
  291. #ifndef powerc
  292.     (void)SetA4(cura4);
  293. #endif
  294.     return(ret);
  295.     }
  296.  
  297. Boolean HasGetScreenWidth()
  298.     {
  299.     return(gacc.GetScreenWidth_Ext != NULL);
  300.     }
  301.  
  302. void SetWatchCursor()
  303.     {
  304.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  305. #ifndef powerc
  306.     long cura4 = SetA4(_app_a4);
  307. #endif
  308.     if (laccp->SetWatchCursor_Ext != NULL)
  309.         (*(laccp->SetWatchCursor_Ext))();
  310. #ifndef powerc
  311.     (void)SetA4(cura4);
  312. #endif
  313.     }
  314.  
  315. Boolean HasSetWatchCursor()
  316.     {
  317.     return(gacc.SetWatchCursor_Ext != NULL);
  318.     }
  319.  
  320. void DoEventLoopOnce()
  321.     {
  322.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  323. #ifndef powerc
  324.     long cura4 = SetA4(_app_a4);
  325. #endif
  326.     if (laccp->DoEventLoopOnce_Ext != NULL)
  327.         (*(laccp->DoEventLoopOnce_Ext))();
  328. #ifndef powerc
  329.     (void)SetA4(cura4);
  330. #endif
  331.     }
  332.  
  333. Boolean HasDoEventLoopOnce()
  334.     {
  335.     return(gacc.DoEventLoopOnce_Ext != NULL);
  336.     }
  337.  
  338. Handle GetTheClip()
  339.     {
  340.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  341.     Handle    ret;
  342. #ifndef powerc
  343.     long cura4 = SetA4(_app_a4);
  344. #endif
  345.     if (laccp->GetAppClip_Ext != NULL)
  346.         ret = (*(laccp->GetAppClip_Ext))();
  347.     else
  348.         ret = NULL;
  349. #ifndef powerc
  350.     (void)SetA4(cura4);
  351. #endif
  352.     return(ret);
  353.     }
  354.  
  355. Boolean HasGetTheClip()
  356.     {
  357.     return(gacc.GetAppClip_Ext != NULL);
  358.     }
  359.  
  360. // Note for version 3 the version is signalled by long extendID == 'VER3'
  361. // inside gacc -- for previous versions, the odds of this long being set
  362. // to exactly 'VER3' are very small.
  363.  
  364. short PutTheClip(char *newClipStr)
  365.     {
  366.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  367.     short    ret = 0;
  368. #ifndef powerc
  369.     long cura4 = SetA4(_app_a4);
  370. #endif
  371.     if (laccp->extendID == 'VER3' && laccp->PutAppClip_Ext != NULL)
  372.         ret = (*(laccp->PutAppClip_Ext))(newClipStr);
  373. #ifndef powerc
  374.     (void)SetA4(cura4);
  375. #endif
  376.     return(ret);
  377.     }
  378.  
  379. Boolean HasPutTheClip(void)
  380.     {
  381.     return(gacc.extendID == 'VER3' && gacc.PutAppClip_Ext != NULL);
  382.     }
  383.  
  384.